home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.07 Jul 93 / Bedrock Header Files / Strings Includes / BRPasStr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-19  |  10.4 KB  |  285 lines  |  [TEXT/MPS ]

  1. #ifndef BRPASSTR_H
  2. #define BRPASSTR_H
  3. //========================================================================================
  4. //
  5. //     File:        BRPasStr.h
  6. //     Release Version:    $ 1.0d1 $
  7. //
  8. //     Creation Date:    4/2/93
  9. //
  10. //     COPYRIGHT 1993 SYMANTEC CORPORATION. ALL RIGHTS RESERVED. UNPUBLISHED -- RIGHTS
  11. //     RESERVED UNDER THE COPYRIGHT LAWS OF THE UNITED STATES. USE OF COPYRIGHT NOTICE IS
  12. //     PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION OR DISCLOSURE.
  13. //
  14. //     THIS SOFTWARE CONTAINS PROPRIETARY AND CONFIDENTIAL INFORMATION OF SYMANTEC
  15. //     CORPORATION. USE, DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR
  16. //     EXPRESS WRITTEN PERMISSION OF SYMANTEC CORPORATION.
  17. //
  18. //     RESTRICTED RIGHTS LEGEND
  19. //     Use, duplication, or disclosure by the Government is subject to restrictions as set
  20. //     forth in subparagraph (c)(l)(ii) of the Rights in Technical Data and Computer
  21. //     Software clause at DFARS 252.227-7013. Symantec Corporation, 10201 Torre Avenue,
  22. //     Cupertino, CA 95014.
  23. //
  24. //========================================================================================
  25.  
  26. #ifndef BRTSTRS_H
  27. #include "BRTStrs.h"
  28. #endif
  29.  
  30. #ifndef BRCHARAC_H
  31. #include "BRCharac.h"
  32. #endif
  33.  
  34. //========================================================================================
  35. //    CLASS BR_TPascalString
  36. //========================================================================================
  37.  
  38. template <unsigned char tCapacity>
  39. class BR_TPascalStringWriter;
  40.  
  41. template <unsigned char tCapacity>
  42. class BR_TPascalString : public BR_TString<BR_Char>
  43. {
  44.     friend class BR_TPascalStringWriter<tCapacity>;
  45.  
  46. public:
  47.  
  48.     ~BR_TPascalString();
  49.     BR_TPascalString();
  50.  
  51.     BR_TPascalString(const BR_TPascalString<tCapacity> &string);
  52.     BR_TPascalString(const BR_TString<BR_Char> &string);
  53.     BR_TPascalString(const BR_Char *items, BR_CharacterCount numberItems);
  54.  
  55.     BR_TPascalString(const BR_Char *string);
  56.         // string points to first character of NUL-terminated string
  57.  
  58.     BR_TPascalString(const BR_PascalChar *string);
  59.         // string points to length byte of pascal string storage
  60.  
  61.     BR_TString<BR_Char>& operator=(const BR_TString<BR_Char> &string);
  62.     BR_TString<BR_Char>& operator=(const BR_Char *string);
  63.         // string points to first character of NUL-terminated string
  64.  
  65.     BR_TString<BR_Char>& operator=(const BR_PascalChar* string);
  66.         // string points to length byte of pascal string storage
  67.  
  68.     BR_CharacterCount GetCapacity() const;
  69.  
  70.     virtual BR_CharacterCount GrowCapacity(BR_CharacterCount capacityNeeded);
  71.         // Called only when changing capacity from amount allocated by constructor.
  72.  
  73.     virtual void Retrieve(BR_Char* items, BR_CharacterCount numberItems, BR_CharacterPosition position) const;
  74.         // Retrieve numberItems of items starting at position.
  75.         
  76.     virtual void Replace(const BR_Char* items, BR_CharacterCount numberItems, BR_CharacterPosition position);
  77.         // Replace numberItems of items starting at position.
  78.  
  79.     virtual void Insert(const BR_Char* items, BR_CharacterCount numberItems, BR_CharacterPosition position);
  80.         // Insert characters into string just before the character at positition.
  81.         // Insert at position GetLength() appends the characters.
  82.         // Insert at position 0 prepends the characters.
  83.         
  84.     virtual void Delete(BR_CharacterCount numberItems, BR_CharacterPosition position);
  85.         // Delete numberItems characters, starting at position.
  86.         
  87.     virtual operator const BR_Char*() const;
  88.         // Return a pointer to the first character in the string.
  89.  
  90.     virtual operator const BR_PascalChar*() const;
  91.         // Return a pointer to the length byte of the string.
  92.  
  93.     virtual BR_Char& operator[](BR_CharacterPosition position);
  94.         // Retrieve by reference the character at given position.
  95.         // The length byte cannot be accessed.
  96.         // The NUL-terminator at position=fLength cannot be accessed.
  97.         
  98.     void ExportPascal(BR_Char* buffer) const;
  99.         // Copy contents of this string to external buffer.
  100.         // buffer will contain pascal string string with length byte at buffer[0].
  101.         // It is client's responsibilitiy to ensure buffer is large enough.
  102.  
  103.     void ExportPascal(BR_PascalChar* buffer) const;
  104.         // Copy contents of this string to external buffer.
  105.         // buffer will contain pascal string string with length byte at buffer[0].
  106.         // It is client's responsibilitiy to ensure buffer is large enough.
  107.  
  108. protected:
  109.     enum { kLengthByte = 0 };
  110.     
  111.     BR_Char    fStorage[tCapacity+2];
  112.  
  113.     void SetLength(unsigned char length);
  114. };
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    BR_TPascalString<tCapacity>::GetCapacity
  118. //----------------------------------------------------------------------------------------
  119.  
  120. template <unsigned char tCapacity>
  121. inline BR_CharacterCount BR_TPascalString<tCapacity>::GetCapacity() const
  122. {
  123.     return tCapacity;
  124. }
  125.  
  126. //----------------------------------------------------------------------------------------
  127. //    BR_TString<tCharacter>::ExportPascal
  128. //----------------------------------------------------------------------------------------
  129.  
  130. template <unsigned char tCapacity>
  131. inline void BR_TPascalString<tCapacity>::ExportPascal(BR_Char* buffer) const
  132. {
  133.     BR_BlockMove((const BR_PascalChar*)(*this), (BR_PascalChar*)buffer, GetLength()+1);
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. //    BR_TString<tCharacter>::ExportPascal
  138. //----------------------------------------------------------------------------------------
  139.  
  140. template <unsigned char tCapacity>
  141. inline void BR_TPascalString<tCapacity>::ExportPascal(BR_PascalChar* buffer) const
  142. {
  143.     BR_BlockMove((const BR_PascalChar*)(*this), buffer, GetLength()+1);
  144. }
  145.  
  146. //----------------------------------------------------------------------------------------
  147. //    BR_TPascalString<tCapacity>::SetLength
  148. //----------------------------------------------------------------------------------------
  149.  
  150. template <unsigned char tCapacity>
  151. void BR_TPascalString<tCapacity>::SetLength(unsigned char length)
  152. {
  153.     fLength = length;
  154.     fStorage[kLengthByte] = fLength;
  155.     fStorage[fLength+1] = kNulCharacter;
  156. }
  157.  
  158. //========================================================================================
  159. //    CLASS BR_CUniversalPascalStringReader
  160. //========================================================================================
  161.  
  162. class BR_CUniversalPascalStringReader : public BR_TUniversalStringReader<BR_Char>
  163. {
  164. public:
  165.     BR_CUniversalPascalStringReader(const BR_TString<BR_Char> &string) :  
  166.         BR_TUniversalStringReader<BR_Char>(string) {}
  167. };
  168.  
  169. //========================================================================================
  170. //    CLASS BR_CPascalString255
  171. //========================================================================================
  172.  
  173. const unsigned char BR_kPascalString255Capacity = 255;
  174.  
  175. class BR_CPascalString255 : public BR_TPascalString<BR_kPascalString255Capacity>
  176. {
  177. public:
  178.  
  179.     ~BR_CPascalString255();
  180.     BR_CPascalString255();
  181.  
  182.     BR_CPascalString255(const BR_TString<BR_Char> &string);
  183.     BR_CPascalString255(const BR_Char *items, BR_CharacterCount numberItems);
  184.  
  185.     BR_CPascalString255(const BR_Char *string);
  186.         // string points to first character of NUL-terminated string
  187.  
  188.     BR_CPascalString255(const BR_PascalChar *string);
  189.         // string points to length byte of pascal string storage
  190.  
  191.     BR_TString<BR_Char>& operator=(const BR_TString<BR_Char> &string);
  192.     BR_TString<BR_Char>& operator=(const BR_Char *string);
  193.         // string points to first character of NUL-terminated string
  194.  
  195.     BR_TString<BR_Char>& operator=(const BR_PascalChar* string);
  196.         // string points to length byte of pascal string storage
  197.  
  198. };
  199.  
  200. //========================================================================================
  201. //    CLASS BR_CPascalString255
  202. //========================================================================================
  203.  
  204. const unsigned char BR_kPascalString32Capacity = 32;
  205.  
  206. class BR_CPascalString32 : public BR_TPascalString<BR_kPascalString32Capacity>
  207. {
  208. public:
  209.  
  210.     ~BR_CPascalString32();
  211.     BR_CPascalString32();
  212.  
  213.     BR_CPascalString32(const BR_TString<BR_Char> &string);
  214.     BR_CPascalString32(const BR_Char *items, BR_CharacterCount numberItems);
  215.  
  216.     BR_CPascalString32(const BR_Char *string);
  217.         // string points to first character of NUL-terminated string
  218.  
  219.     BR_CPascalString32(const BR_PascalChar *string);
  220.         // string points to length byte of pascal string storage
  221.  
  222.     BR_TString<BR_Char>& operator=(const BR_TString<BR_Char> &string);
  223.     BR_TString<BR_Char>& operator=(const BR_Char *string);
  224.         // string points to first character of NUL-terminated string
  225.  
  226.     BR_TString<BR_Char>& operator=(const BR_PascalChar* string);
  227.         // string points to length byte of pascal string storage
  228.  
  229. };
  230.  
  231. //========================================================================================
  232. //    CLASS BR_TPascalStringWriter
  233. //========================================================================================
  234.  
  235. template <unsigned char tCapacity>
  236. class BR_TPascalStringWriter : public BR_TTextWriter<BR_Char>
  237. {
  238. public:
  239.     enum {kDefaultExpansion=32};
  240.     
  241.     ~BR_TPascalStringWriter();
  242.     BR_TPascalStringWriter(BR_TPascalString<tCapacity> &string, 
  243.                             BR_TextWriterMode mode=BR_kTextAppend,
  244.                             unsigned short expansion=kDefaultExpansion);
  245.  
  246. protected:
  247.     virtual void FlushAndGetNextBuffer();
  248.         // Flush the current buffer.
  249.         // Get another buffer from string, update fNext and fLimit.
  250.  
  251.     void FlushAndUpdateText();
  252.         // Flush the current buffer.
  253.         // Do whatever may be necessary to restore text structure to valid state,
  254.         // ... e.g. restore NUL termination, cached length member, etc.
  255.         // This method is called from destructor.
  256.  
  257.     BR_TPascalString<tCapacity>    &fString;
  258. };
  259.  
  260. #ifdef qTemplateForwardReferenceCantBeBaseClassBug
  261. //========================================================================================
  262. //    CLASS BR_CPascalString255Writer
  263. //========================================================================================
  264.  
  265. class BR_CPascalString255Writer : public BR_TPascalStringWriter<BR_kPascalString255Capacity>
  266. {
  267. public:
  268.     BR_CPascalString255Writer(BR_CPascalString255 &string, BR_TextWriterMode mode=BR_kTextAppend) :  
  269.         BR_TPascalStringWriter<BR_kPascalString255Capacity>(string, mode) {}
  270. };
  271.  
  272. //========================================================================================
  273. //    CLASS BR_TPascalStringWriter
  274. //========================================================================================
  275.  
  276. class BR_CPascalString32Writer : public BR_TPascalStringWriter<BR_kPascalString32Capacity>
  277. {
  278. public:
  279.     BR_CPascalString32Writer(BR_CPascalString32 &string, BR_TextWriterMode mode=BR_kTextAppend) :  
  280.         BR_TPascalStringWriter<BR_kPascalString32Capacity>(string, mode) {}
  281. };
  282. #endif
  283.  
  284. #endif
  285.